package JDBC;

import java.awt.*;
import java.net.URI;
import java.sql.*;
import java.util.Scanner;

public class Connect1 {


    public static void InsertValue(String username,String pwd ) throws Exception {
        Connection connection = JDBCUtils.getConnection();
        String sql = "insert  into user1 values (null,?,?)";

        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1,username);
        statement.setString(2,pwd);
        statement.executeUpdate();
        JDBCUtils.closeAll(connection,statement);
    }
    public static void SelValue(String username,String pwd ) throws Exception {
        Connection connection = JDBCUtils.getConnection();
        String sql = "select  * from user1 ";
        Statement statement = connection.prepareStatement(sql);
        ResultSet resultSet = statement.executeQuery(sql);
        while (true) {
            if (resultSet.next()) {
                String a = resultSet.getString(2);
                String b = resultSet.getString(3);
                if (a.equals(username)) {
                    while (true) {
                        if (b.equals(pwd)) {
                            URI uriNet = new URI("www.baidu.com");
                            Desktop.getDesktop().browse(uriNet);
                            break;
                        } else {
                            System.out.println("密码错误请重新输入");
                            pwd = new Scanner(System.in).nextLine();
                        }
                    }
                    break;
                }

            } else {
                System.out.println("登陆失败，用户名不存在！");
                break;

            }

        }

        JDBCUtils.closeAll(connection,statement);
    }
}
